/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package num7;

import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Usuário
 */
public abstract class ListaTemplate {

    
    
    public final void listaTels(menuView view) {
        ArrayList<ListaModel> li = lerContatos();
        exibirListaAntiga(li, view);
        exibirListaSolicitada(li, view);
//        obterListaTelefonica();
//        listarNomes();
    }
    
//    public void obterListaTelefonica(){
//    }
//    public void listarNomes(){
//    }
//    public abstract void obterNumerosDeTelefone();
    

    private void exibirListaAntiga(ArrayList<ListaModel> li, menuView view) {
        
        view.setVisible(true);
        
        Object colunas[] = {"ID", "UF", "Nome", "Numero", "Operadora"};
        DefaultTableModel tmUsuario = new DefaultTableModel(colunas, 0) {
            @Override
            public boolean isCellEditable(int row, int col) {
                if (col == 0 || col == 1) {
                    return false;
                } else {
                    return true;
                }
            }
        };
        for (int i = 0; i < li.size(); i++) {
            ListaModel l = li.get(i);
            tmUsuario.addRow(new Object[]{l.getNome(), l.getId(), l.getNumero(), l.getUf(), l.getOperadora()});
        }
        view.getTableListaAntiga().setModel(tmUsuario);
    }
    
    private ArrayList<ListaModel> lerContatos(){
        Persistencia p = new Persistencia();
        ArrayList<ListaModel> lista = p.lerContatos();
        return lista;
    }

    public abstract void exibirListaSolicitada(ArrayList<ListaModel> li, menuView view);
}
